/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK 1.6+
 * <p>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p>
 * 公司名称：江苏欧索软件有限公司
 * <p>
 * 公司地址：中国苏州科技城青山路1号
 * <p>
 * 网址: http://www.oceansoft.com.cn
 * <p>
 * 作者: 090922(陈伟)
 * <p>
 * 文件名: com.oceansoft.mobile.biz.front.controller.ChannelController.java
 * <p>
 * 类产生时间: 2014/3/27 21:12
 * <p>
 * 负责人: 090922(陈伟)
 * <p>
 * Email:javacspring@gmail.com
 * <p>
 * 所在组 : 掌上公安应用平台
 * <p>
 * 所在部门: 开发部--手持技术部
 * <p>
 * <p>
 */
package com.oceansoft.mobile.biz.front.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oceansoft.mobile.biz.admin.entity.NewsArticle;
import com.oceansoft.mobile.biz.admin.entity.Wxjq;
import com.oceansoft.mobile.biz.admin.service.INewsService;
import com.oceansoft.mobile.biz.api.service.IApiWxjqService;
import com.oceansoft.mobile.common.base.entity.Pager;

/**
 * 苏州公安前端控制器
 * 
 * @author Administrator
 * 
 */
@Controller
@RequestMapping("police")
public class PoliceFrontController {
	@Resource
	private INewsService newsService;
	@Resource
	private IApiWxjqService wxService;

	@RequestMapping(value = "newslist", method = RequestMethod.GET)
	public String newslist(Model model) throws ParseException {
//		List<String> newsTime = newsService.showTimes(10);
//		Map<String, List<NewsArticle>> maps = new LinkedHashMap<String, List<NewsArticle>>();
//		for (String string : newsTime) {
//			List<NewsArticle> articles = new ArrayList<NewsArticle>();
//			String date = string.substring(0, 10);
//			articles = newsService.newsList(date);
//			maps.put(date, articles);
//		}
//		model.addAttribute("newsMap", maps);
    	model.addAttribute("themeId", "3");
		List<List<NewsArticle>> grouplist = new ArrayList<List<NewsArticle>>();
		for (NewsArticle article : newsService.findPubTopNews(1000)) {
			List<NewsArticle> list = new ArrayList<NewsArticle>();
			list.add(article);
			list.addAll(newsService.findNewsByTopNews(article.getSid()));
			grouplist.add(list);
		}
		model.addAttribute("grouplist", grouplist);
		return "mobile/police/news-list";
	}

	/**
	 * 办事指南
	 * 
	 * @return
	 */
	@RequestMapping(value = "catalogs", method = RequestMethod.GET)
	public String catalogs() {
		return "mobile/police/work-catalogs";
	}

	/**
	 * 下载页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "download", method = RequestMethod.GET)
	public String download() {
		return "mobile/police/download";
	}

	/**
	 * 部门职能介绍 DepartIntro
	 * 
	 * @return
	 */
	@RequestMapping(value = "departIntro", method = RequestMethod.GET)
	public String departIntro() {
		return "mobile/police/work-departIntro";
	}

	/**
	 * 跳转到部门办事事项
	 * 
	 * @param id
	 *            警钟的id
	 * @param jz
	 *            警钟名称
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "SMatter", method = RequestMethod.GET)
	public String gotoSMatterList(
			@RequestParam(value = "id", required = true) String id, Model model) {
		model.addAttribute("sid", id);
		// 市局为1
		model.addAttribute("bureaus", -1);
		return "mobile/police/work-SMatter";
	}
	
	/**
	 * 跳转到部门办事事项（分局的）
	 * 
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "FMatter", method = RequestMethod.GET)
	public String gotoFMatterList(
			@RequestParam(value = "id", required = true) String id, Model model) {
		// 分局的ID
		model.addAttribute("fid", id);
		// 分局为2
		model.addAttribute("bureaus", 2);
		return "mobile/police/work-SMatter";
	}

	/**
	 * 市局或者分局查询
	 * 
	 * @return
	 */
	@RequestMapping(value = "bureaus", method = RequestMethod.GET)
	public String information() {
		return "mobile/police/work-bureaus";
	}

	/**
	 * 查询事项详细信息
	 * 
	 * @param dept_type
	 * @param dept_id
	 * @param matterId
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "matters", method = RequestMethod.GET)
	public String gotoMatters(@RequestParam("dept_type") String dept_type,
			@RequestParam("dept_id") String dept_id,
			@RequestParam("matterId") String matterId, Model model) {
		if (dept_id.equals("-1")) {
			dept_id = "1";
		}
		model.addAttribute("dept_type", dept_type);
		model.addAttribute("dept_id", dept_id);
		model.addAttribute("matterId", matterId);
		return "mobile/police/work-SMatterDetail";
	}

	/**
	 * 便民应用主界面
	 * 
	 * @return
	 */
	@RequestMapping(value = "bmyy", method = RequestMethod.GET)
	public String bmyy() {
		return "mobile/police/work-mainbmyy";
	}

	/**
	 * 办件进度查询界面
	 * 
	 * @return
	 */
	@RequestMapping(value = "DoCaseProgressSearch", method = RequestMethod.GET)
	public String DoCaseProgressSearch() {
		return "mobile/police/work-DoCaseProgressSearch";
	}

	/**
	 * 居住证办理进度查询
	 * 
	 * @return
	 */
	@RequestMapping(value = "JuZhuZhengProgress", method = RequestMethod.GET)
	public String JuZhuZhengProgress() {
		return "mobile/police/work-JuZhuZhengProgress";
	}

	/**
	 * 居住证办理点查询
	 * 
	 * @return
	 */
	@RequestMapping(value = "JuZhuZheng", method = RequestMethod.GET)
	public String JuZhuZheng() {
		return "mobile/police/work-JuZhuZheng";
	}

	/**
	 * 重名查询
	 * 
	 * @return
	 */
	@RequestMapping(value = "RenameSearch", method = RequestMethod.GET)
	public String RenameSearch() {
		return "mobile/police/work-RenameSearch";
	}

	/**
	 * 身份证办理进度查询
	 * 
	 * @return
	 */
	@RequestMapping(value = "IDCardProgress", method = RequestMethod.GET)
	public String IDCardProgress() {
		return "mobile/police/work-IDCardProgress";
	}

	/**
	 * 与您互动
	 * 
	 * @return
	 */
	@RequestMapping(value = "ynhd", method = RequestMethod.GET)
	public String ynhd() {
		return "mobile/police/ynhd";
	}

	/**
	 * 联系电话
	 * 
	 * @return
	 */
	@RequestMapping(value = "PhoneNum", method = RequestMethod.GET)
	public String PhoneNum() {
		return "mobile/police/PhoneNum";
	}

	/**
	 * 地图导航
	 * 
	 * @return
	 */
	@RequestMapping(value = "mapgps", method = RequestMethod.GET)
	public String mapGps() {
		return "mobile/police/mapGps";
	}

	/**
	 * 区县微信公众平台
	 * 
	 * @return
	 */
//	@RequestMapping(value = "DistrictWb", method = RequestMethod.GET)
//	public String DistrictWb() {
//		return "mobile/police/DistrictWb";
//	}
	
	/**
	 * 微信集群类别选择
	 * 
	 * @return
	 */
	@RequestMapping(value = "gotoWechat", method = RequestMethod.GET)
	public String gotoWxjq() {
		return "mobile/police/wxjq-catalogs";
	}
	
	/**
	 * 区县微信公众平台
	 * 
	 * @return
	 */
	@RequestMapping(value = "wechatAccounts", method = RequestMethod.GET)
	public String DistrictWb(HttpServletRequest request,Model model) {
		String title = request.getParameter("title");
		int pageindex = Integer.parseInt(request.getParameter("pageindex"));
		int areaId = Integer.parseInt(request.getParameter("areaId"));
		Pager<Wxjq> page = wxService.queryWxjq2(title, pageindex,areaId);
//		Pager<Wxjq> page = wxService.queryWxjq(title, pageindex);
		model.addAttribute("wxjqList",page.getRows());
		model.addAttribute("page",page);
		model.addAttribute("areaId",areaId);
		return "mobile/police/wechatAccounts";
	}
	
	/**
	 * 区县微信公众平台
	 * 
	 * @return
	 */
	@RequestMapping(value = "DistrictWb2", method = RequestMethod.GET)
	@ResponseBody
	public Object DistrictWb2(HttpServletRequest request,Model model) {
		String _title = request.getParameter("title");
		int areaId = Integer.parseInt(request.getParameter("areaId"));
		String title="";
		try {
			title = URLDecoder.decode(_title, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		int pageindex = Integer.parseInt(request.getParameter("pageindex"));
//		Pager<Wxjq> page = wxService.queryWxjq(title, pageindex);
		Pager<Wxjq> page = wxService.queryWxjq2(title, pageindex,areaId);
		JSONObject json = JSONObject.fromObject(page);
		return json;
	}

	/**
	 * 违章查询
	 * 
	 * @return
	 */
	@RequestMapping(value = "gotoWZCX", method = RequestMethod.GET)
	public String gotoWZCX() {
		return "mobile/police/work-WZCX";
	}

	/**
	 * 违章查询结果
	 * 
	 * @return
	 */
	@RequestMapping(value = "gotoWZCXInfo", method = RequestMethod.GET)
	public String gotoWZCXInfo(Model model,HttpServletRequest request) throws Exception{
		String caridone = request.getParameter("CarId_one");
		
		if(StringUtils.isNotEmpty(caridone))
			caridone = URLDecoder.decode(caridone, "utf-8");
		
		model.addAttribute("CarId_one", caridone);
		model.addAttribute("CarId_two", request.getParameter("CarId_two"));
		model.addAttribute("drive_license", request.getParameter("drive_license"));
		model.addAttribute("fn", request.getParameter("fn"));
		model.addAttribute("carordriver", request.getParameter("carordriver"));
		return "mobile/police/work-WZCXInfo";
	}

	@RequestMapping(value = "WZCXDetail", method = RequestMethod.GET)
	public String WZCXDetail(@RequestParam("data") String data, Model model) throws Exception{
		model.addAttribute("data", URLDecoder.decode(data, "utf-8"));
		return "mobile/police/work-WZCXDetail";
	}

	/**
	 * 路况播报
	 * 
	 * @return
	 */
//	@RequestMapping(value = "gotoLKBB", method = RequestMethod.GET)
//	public String gotoLKBB() {
//		return "mobile/police/LKBB";
//	}
	
	/**
	 * 实时路况
	 * 
	 * @return
	 */
	@RequestMapping(value = "gotoSSLK", method = RequestMethod.GET)
	public String gotoSSLK() {
		return "mobile/police/SSLK";
	}

}